/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.client.view;

import org.lucava.lib.client.view.MvcView;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import org.lucava.boatskeeper.client.event.DisconnectEvent;
import org.lucava.boatskeeper.client.event.boat.EditBoatEvent;
import org.lucava.boatskeeper.client.event.boat.ListBoatsEvent;
import org.lucava.boatskeeper.client.event.boat.ListUserBoatsEvent;
import org.lucava.boatskeeper.client.event.category.EditCategoryEvent;
import org.lucava.boatskeeper.client.event.category.ListCategoriesEvent;
import org.lucava.boatskeeper.client.event.user.EditSessionUserEvent;
import org.lucava.boatskeeper.client.event.user.EditUserEvent;
import org.lucava.boatskeeper.client.event.user.ListUsersEvent;

/**
 *
 * @author glenn
 */
public class MenuView extends MvcView {

    Label userName;
    Hyperlink linkBoats;
    Hyperlink linkEdit;
    Hyperlink linkDiscon;

    public MenuView(EventBus eventBus) {
        super(eventBus);

        MenuBar menu = new MenuBar();
        menu.setAnimationEnabled(true);

        menu.addItem(new MenuItem("Mon Compte", getAccountMenu()));
        menu.addItem(new MenuItem("Gestion des bateaux", getBoatMenu()));
        menu.addItem(new MenuItem("Gestion des utilisateurs", getUserMenu()));

        initWidget(menu);
    }

    private MenuBar getAccountMenu() {

        MenuBar accountMenu = new MenuBar(true);

        MenuItem editItem = accountMenu.addItem("Modifier", new Command() {
            @Override
            public void execute() {
                fireEvent(new EditSessionUserEvent());
            }
        });

        MenuItem discItem = accountMenu.addItem("Se déconnecter", new Command() {
            @Override
            public void execute() {
                fireEvent(new DisconnectEvent());
            }
        });

        return accountMenu;
    }

    private MenuBar getBoatMenu() {

        MenuBar boatMenu = new MenuBar(true);

        MenuItem boatsItem = boatMenu.addItem("Voir tous les bateaux", new Command() {
            @Override
            public void execute() {
                fireEvent(new ListBoatsEvent());
            }
        });

        MenuItem addBoatItem = boatMenu.addItem("Ajouter un bateau", new Command() {
            @Override
            public void execute() {
                fireEvent(new EditBoatEvent(null));
            }
        });
        MenuItem showCatItem = boatMenu.addItem("Voir les catégories", new Command() {
            @Override
            public void execute() {
                fireEvent(new ListCategoriesEvent());
            }
        });


        MenuItem addCatItem = boatMenu.addItem("Ajouter une catégorie", new Command() {
            @Override
            public void execute() {
                fireEvent(new EditCategoryEvent(null));
            }
        });



        return boatMenu;

    }

    private MenuBar getUserMenu() {

        MenuBar userMenu = new MenuBar(true);

        MenuItem usersItem = userMenu.addItem("Voir tous les utilisteurs", new Command() {
            @Override
            public void execute() {
                fireEvent(new ListUsersEvent());
            }
        });
        MenuItem addUserItem = userMenu.addItem("Ajouter un utilisteur", new Command() {
            @Override
            public void execute() {
                fireEvent(new EditUserEvent(null));
            }
        });


        return userMenu;
    }
}
